package Operation;

import controller.DataAccessHandler;
import model.pojo.Account;

import java.util.List;

/**
 * 查询所有账号和密码
 */
public class SearchAllOperationIOperation implements IOperation {
    @Override
    public void operate() {
        System.out.println("<查询所有账户信息>");
        // 访问数据库，执行sql语句
        String sql = "select account_id as accountId,keyword,account_number as accountNumber," +
                "password,remark,creation_time as creationTime,last_modification_time as lastModificationTime " +
                "from tb_accounts";
        List<Account> accounts = DataAccessHandler.query(Account.class, sql);
        // 打印查询结果
        if(accounts != null && accounts.size() != 0){
            for (Account account : accounts){
                System.out.println(account);
            }
        }else{
            System.out.println("Memory repository is empty!");
        }
    }
}
